local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) 		end
function onCreatureDisappear(cid) 			npcHandler:onCreatureDisappear(cid) 		end
function onCreatureSay(cid, type, msg) 			npcHandler:onCreatureSay(cid, type, msg) 	end
function onThink() 					npcHandler:onThink() 				end

function returnVials(cid, message, keywords, parameters, node)
	if(npcHandler.focus ~= cid) then
		return false
	end
	
	local amount = removePlayerItemsWithCharges(cid, parameters.itemid, parameters.charges)
	if(amount <= 0) then
		npcHandler:say('You do not have any.')
	else
		local price = amount*parameters.cost
		if(doPlayerAddMoney(cid, price) == LUA_NO_ERROR) then
			npcHandler:say('Here are your reward of ' .. price .. ' gold coins. It was a pleasure doing business with you.')
		else
			error('[Error] returnVials:', 'Could not give ' .. price .. ' gold coins to player ' .. getPlayerName(cid))
		end
	end
	npcHandler:resetNpc()
	return true
end


local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

keywordHandler:addKeyword({'missile runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell light magic missile(0,5k), heavy magic missile(1k) and sudden death(6k) runes.'})
keywordHandler:addKeyword({'explosive runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell fireball(1k), great fireball(2k) and explosion(4k) runes.'})
keywordHandler:addKeyword({'field runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell fire field(85gp), energy field(115gp), poison field(65gp) and destroy field(45gp) runes.'})
keywordHandler:addKeyword({'wall runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell fire wall(245gp), energy wall(340gp) and poison wall(210gp) runes. I also sell magic wall runes for 350gp.'})
keywordHandler:addKeyword({'bomb runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell fire bomb(210gp), poison bomb(170gp) and energy bomb(325gp) runes.'})
keywordHandler:addKeyword({'healing runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell antidote(65gp), intense healing(95gp) and ultimate healing(3k) runes.'})
keywordHandler:addKeyword({'other spell runes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell convince creature(80gp) and chameleon(210gp) runes, but also envenom(130gp), desintegrate(80gp), soulfire(210gp) and paralyze(1000gp).'})
keywordHandler:addKeyword({'wands'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell wand of vortex(free), magic lightwand(500gp), dragonbreath(1k), plague(5k), cosmic energy(10k) and inferno(15k).'})
keywordHandler:addKeyword({'rods'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell snakebite(free), moonlight(1k), volcanic(5k), quarmire(10k) and tempest rods(15k).'})
keywordHandler:addKeyword({'fluids'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell mana(55gp) and life(60gp) fluids.'})

shopModule:addBuyableItem({'mana fluid', 'manafluid', 'mf', 'mrune', 'manarune', 'mana rune', 'manarunes', 'mana runes'}, 	2298, 500, 	3, 	'mana fluid')

shopModule:addBuyableItem({'blank rune', 'br'}, 		2260, 10, 1,		'blank rune')

shopModule:addBuyableItem({'sudden death', 'sd'}, 		2268, 1000, 2, 		'sudden death rune')

shopModule:addBuyableItem({'great fireball', 'gfb'}, 		2304, 180, 2, 		'great fireball rune')
shopModule:addBuyableItem({'explosion', 'explo'}, 		2313, 1000, 2, 		'explosion rune')


shopModule:addBuyableItem({'destroy field', 'df'}, 		2261, 45,  1, 		'destroy field')


shopModule:addBuyableItem({'magic wall', 'mw'}, 		2293, 500, 3,		'magic wall rune')

shopModule:addBuyableItem({'fire bomb'}, 			2305, 235, 3,		'fire bomb rune')


shopModule:addBuyableItem({'ultimate healing', 'uh'}, 		2273, 500, 2, 		'ultimate healing rune')


shopModule:addBuyableItem({'paralyze'}, 			2278, 500, 3, 		'paralyze rune')


shopModule:addBuyableItem({'spell book'}, 			2217, 150, 		'spell book')





local node = keywordHandler:addKeyword({'flask'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you wish to return all your empty vials for 5 gold coins each?'})
	node:addChildKeyword({'yes'}, returnVials, {itemid = 2006, charges = 0, cost = 5})
	node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Allright then.'})

local node = keywordHandler:addKeyword({'vial'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you wish to return all your empty vials for 5 gold coins each?'})
	node:addChildKeyword({'yes'}, returnVials, {itemid = 2006, charges = 0, cost = 5})
	node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Allright then.'})

npcHandler:addModule(FocusModule:new())